package com.Smart.smartscals.Adapter;

import java.util.ArrayList;

import com.Smart.smartscals.Activity.R;
import com.Smart.smartscals.Entity.EntityListView;
import com.Smart.smartscals.Fragment.BaseFragment;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsoluteLayout;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 
 * @author huangbin
 * 
 *         Fragment_name_main里面的ListView 的适配器
 */
public class SlideAdapter extends BaseAdapter {

	private ArrayList<EntityListView> arrayListViews;
	private Context mContext;
	private ListView mListView;

	class ViewHoder {
		public ImageView imgBg;
		public TextView tv1;
	}

	public SlideAdapter(ListView mListView,ArrayList<EntityListView> arrayListViews,
			Context mContext) {
		super();
		this.mListView = mListView;
		this.arrayListViews = arrayListViews;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return arrayListViews.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayListViews.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int pos, View contentView, ViewGroup arg2) {
		ViewHoder hoder = new ViewHoder();
		if (contentView == null) {
			contentView = LayoutInflater.from(mContext).inflate(
					R.layout.main_slid_listitem, null);
			//动态设置高度
			AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
			layoutParams.height = mListView.getHeight()/8;
			contentView.setLayoutParams(layoutParams);
			
			
			hoder.imgBg = (ImageView) contentView
					.findViewById(R.id.main_aboutus_factory_author_img);
			hoder.tv1 = (TextView) contentView
					.findViewById(R.id.main_aboutus_factory_author_tv);
			

			contentView.setTag(hoder);

		} else {
			hoder = (ViewHoder) contentView.getTag();
			


		}
		hoder.imgBg.setBackgroundResource(arrayListViews.get(pos).getImgBg());
		// 设置显示内容
		hoder.tv1.setText(arrayListViews.get(pos).getTvStr1());
		

		return contentView;
	}

}
